warning('off')
load('BloombergData20240205Govt.mat')
clear ind;
for i=1:length(AllDates)
    ind(i)=sum(abs(bonddat(i,2,1:63)))>0;
end
AllDates2=AllDates(ind);
bonddat2=bonddat(ind,:,:);
NoTwins=9;
X=zeros(length(AllDates2),NoTwins);
re=zeros(NoTwins+1,3);
for TwinNo=1:NoTwins
    TwinBonds_v2_update
    GBprem=100*diff(squeeze(bonddat2(:,2,[greenbond blackbond]))');
    GBprem(1:eday-1)=NaN;
    X(:,TwinNo)=GBprem;
    txt{TwinNo}=bondtxt;
    Y=GBprem;
    Xreg=ones(length(Y),1);
    lm = fitlm(Xreg,Y,'Intercept',false);
    re(TwinNo,1)=lm.Coefficients.Estimate(1);
    ind=isnan(Y)==0;
    re(TwinNo,2)=NeweyWest(lm.Residuals.Raw(ind),Xreg(ind),12,0);
    re(TwinNo,3)=median(GBprem(ind));
    re(TwinNo,4)=min(GBprem(ind));
    re(TwinNo,5)=max(GBprem(ind));
    re(TwinNo,6)=sum(ind);
end

Y=nanmean(X');
Y=Y(isnan(Y)==0);
Xreg=ones(length(Y),1);
lm = fitlm(Xreg,Y,'Intercept',false);
re(NoTwins+1,1)=lm.Coefficients.Estimate(1);
re(NoTwins+1,2)=NeweyWest(lm.Residuals.Raw,Xreg,12,0);
txt{NoTwins+1}='Average';
re(NoTwins+1,3)=median(Y);
re(NoTwins+1,4)=min(Y);
re(NoTwins+1,5)=max(Y);
re(NoTwins+1,6)=length(Y);


clear CARtxt; CARtxt{1}='CSC(0)'; CARtxt{2}='CSC(0,4)'; CARtxt{3}='CSC(-6,4)'; 
li=[0.95 0.975 0.995];
qq=norminv(li);
prec0='%11.0f'; prec1='%11.1f'; prec2='%11.2f';
str='\begin{table}[h]\begin{center}\begin{tabular}{cccccc}\hline ';
str=[str '&Mean & Median & Min & Max & N\\\hline '];
for TwinNo=1:(NoTwins+1)
    str=[str txt{TwinNo} '&$' num2str(re(TwinNo,1),prec2) '^{'];
    for u=1:length(qq), if abs(re(TwinNo,1)/re(TwinNo,2))>qq(u), str=[str '*']; else end; end  
    str=[str '}$'];
    for s=3:5
        str=[str '&' num2str(re(TwinNo,s),prec2)];
    end
    str=[str '&' num2str(re(TwinNo,6),prec0) '\\'];
    str=[str '&\begin{scriptsize}(' num2str(re(TwinNo,2),prec2) ')\end{scriptsize}&&&&\\ '];
end
str=[str '\hline \end{tabular}\end{center}'];
str



